import time
def bubble_sort(a):
    n = len(a)
    for i in range(n):
        swapped = False
        for j in range(0, n-i-1):
            if a[j] > a[j+1]:
                a[j], a[j+1] = a[j+1], a[j]
                swapped = True
        if not swapped:
            break

    return a

file_names = ['m1_sorted.txt', 'm2_reverse.txt', 'm3_shuffle.txt']
for file in file_names:
    with open(file, 'r') as f:
        b = [int(line) for line in f]
        start_time = time.time()
        bubble_sort(b)
        end_time = time.time()
        duration = int(round((end_time - start_time) * 1000))
        file_name_parts = file.split('.')
        file_name = file_name_parts[0]
        print(f"{file_name}  {duration} milliseconds")